<template>
	<view class="warning-detail-container">
		<view class="warning-detail-top">
			<u-tabs
				:list="tabList"
				:activeStyle="{
					color: '#0071F7',
					fontWeight: 'bold',
					transform: 'scale(1.05)'
				}"
				@change="changeTab"
				:current="currentTab"
			></u-tabs>
		</view>
		<view class="filter-container" v-if="hasFilter">
			<u-subsection :list="list" :current="current" mode="subsection" inactiveColor="#0071F7" @change="changeSubsection"></u-subsection>
		</view>
		<view class="tips-container" v-if="isSpecial && consecutiveAbsenteeismForStayingDays">
			<u-icon name="error-circle-fill" size="18" color="#FA5151" />
			<text class="tip">在岗人员连续{{ consecutiveAbsenteeismForStayingDays }}天未出勤</text>
		</view>
		<scroll-view class="scroll-view" scroll-y>
			<IdentityNumberExpired v-show="tabList[currentTab].code == 'identityNumberExpired'" :projectUuid="projectUuid" ref="identityNumberExpired"></IdentityNumberExpired>
			<ElderAge
				v-show="tabList[currentTab].code == 'elderAge'"
				:current="current"
				:projectUuid="projectUuid"
				:currentTabCode="tabList[currentTab].code"
				ref="elderAge"
			></ElderAge>
			<OverAge
				v-show="tabList[currentTab].code == 'overAge'"
				:current="current"
				:projectUuid="projectUuid"
				:currentTabCode="tabList[currentTab].code"
				ref="overAge"
			></OverAge>
			<CertificateExpired v-show="tabList[currentTab].code == 'certificateExpire'" :projectUuid="projectUuid" ref="certificateExpire"></CertificateExpired>
			<NoAttendanceRecordForStay
				v-show="tabList[currentTab].code == 'noAttendanceRecordForStay'"
				:projectUuid="projectUuid"
				ref="noAttendanceRecordForStay"
			></NoAttendanceRecordForStay>
		</scroll-view>
	</view>
</template>

<script>
import { common } from '@/pagesA/utils/common.js';
import IdentityNumberExpired from '@/pagesA/pages/projectSurvey/IdentityNumberExpired.vue';
import ElderAge from '@/pagesA/pages/projectSurvey/ElderAge.vue';
import OverAge from '@/pagesA/pages/projectSurvey/OverAge.vue';
import CertificateExpired from '@/pagesA/pages/projectSurvey/CertificateExpired.vue';
import NoAttendanceRecordForStay from '@/pagesA/pages/projectSurvey/NoAttendanceRecordForStay.vue';
const app = getApp();
export default {
	components: {
		IdentityNumberExpired,
		ElderAge,
		OverAge,
		CertificateExpired,
		NoAttendanceRecordForStay
	},
	data() {
		return {
			currentTab: 0,
			tabList: [
				{
					name: '证件过期',
					code: 'identityNumberExpired'
				},
				{
					name: '大龄人员',
					code: 'elderAge'
				},
				{
					name: '超龄人员',
					code: 'overAge'
				},
				{
					name: '证书过期',
					code: 'certificateExpire'
				},
				{
					name: '连续未出勤',
					code: 'noAttendanceRecordForStay'
				}
			],
			list: [],
			elderAgeList: ['全部', '大龄男性', '大龄女性'],
			overAgeList: ['全部', '超龄男性', '超龄女性'],
			current: 0,
			hasFilter: false,
			isSpecial: false,
			projectUuid: '',
			consecutiveAbsenteeismForStayingDays: ''
		};
	},
	onLoad(options) {
		this.projectUuid = !options.projectUuid || options.projectUuid == 'undefined' || options.projectUuid == 'null' ? '' : options.projectUuid;
		let code = options.code;
		for (let i = 0; i < this.tabList.length; i++) {
			if (this.tabList[i].code == code) {
				this.changeTab({
					index: i,
					...this.tabList[i]
				});
				break;
			}
		}
		this.$refs.identityNumberExpired.refreshList();
		if (code != 'elderAge') {
			this.$refs.elderAge.refreshList();
		}
		if (code != 'overAge') {
			this.$refs.overAge.refreshList();
		}
		this.$refs.certificateExpire.refreshList();
		if (app.globalData.consecutiveAbsenteeismForStayingDays) {
			this.consecutiveAbsenteeismForStayingDays = app.globalData.consecutiveAbsenteeismForStayingDays;
			delete app.globalData.consecutiveAbsenteeismForStayingDays;
		}
		this.$refs.noAttendanceRecordForStay.refreshList();
	},
	onShow() {},
	methods: {
		changeTab(item) {
			this.currentTab = item.index;
			this.hasFilter = false;
			this.isSpecial = false;
			if (item.code == 'elderAge' || item.code == 'overAge') {
				this.list = this[item.code + 'List'];
				this.current = '';
				this.$nextTick(() => {
					this.current = 0;
				});
				this.hasFilter = true;
			} else if (item.code == 'noAttendanceRecordForStay') {
				//连续未出勤
				this.isSpecial = true;
			}
		},
		changeSubsection(index) {
			this.current = index;
		}
	}
};
</script>

<style>
.warning-detail-container {
	height: 100vh;
	display: flex;
	flex-direction: column;
	background-color: #f6f7fa;
}
.warning-detail-top {
	background-color: #fff;
}
.filter-container,
.tips-container {
	margin: 24rpx 24rpx 0;
}
.tips-container {
	display: flex;
	align-items: center;
}
.tip {
	margin-left: 16rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #ff555c;
}
.scroll-view {
	height: 0;
	flex: 1;
}
</style>
